clear all;
close all;
Qk=[2,3];
Zk=[0;-2];

T=0.001;
for k=1:1:10000
    time(k)=k*T;
    Ft=2.5*sin(10*pi*time(k));
    if time(k)<5
        dt=0;
    else
        dt=2.5*sin(20*pi*time(k));
    end
    
    y1=Qk(1);y2=Qk(2);
    x1=Zk(1);x2=Zk(2);

    Q(:,k)=[y1;y2];
    Z(:,k)=[x1;x2];
    e(:,k) = Z(:,k)-Q(:,k);

    tSpan=[0 T];
    
    [tt,Qq] = ode45(@(t,x) plant(t,x,dt,Ft),tSpan,Qk);
    Qk = Qq(length(Qq),:);
    [tt1,Zq] = ode45(@(t,x) obv(t,x,dt,y1),tSpan,Zk);
    Zk = Zq(length(Zq),:);

    
end

figure(1);
plot(time,Q(1,:),'k',time,Z(1,:),'r:','linewidth',2);
xlabel('time(s)');ylabel('x1 and its estimate');
legend('x1','Estimate x1');

figure(2);
plot(time,Q(2,:),'k',time,Z(2,:),'r:','linewidth',2);
xlabel('time(s)');ylabel('x2 and its estimate');
legend('x2','Estimate x2');

figure(3);
plot(time,e(1,:),'k','linewidth',2);
xlabel('time(s)');ylabel('x1 observation error');

figure(4);
plot(time,e(2,:),'k','linewidth',2);
xlabel('time(s)');ylabel('x2 observation error,');